home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / ArrayMapperWnd.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  10.6 KB  |  514 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:    July 1, 1997
  22. //  Author:            rh
  23. //
  24. //  Description:
  25. //        Helper dialog to launch the arrayMapper command.
  26. //
  27. //    Contents:
  28. //        makeMonochromRampAMW        Make monochromatic ramp.
  29. //        okayAMW()                Callback for the OK button.
  30. //        makeAttrName()            Create a new attribute name.
  31. //        replaceBtns()            Rebuild the buttons in the menu.
  32. //        makeAryAttrList()        Get all array attributes from shape.
  33. //        create()                Build the dialog.
  34. //        register()                Register the callbacks.
  35. //         ArrayMapperWnd()        Main entry point. Launch dialog.
  36.  
  37.  
  38. global string    $gArrayMapperObject = "";
  39. global string    $gArrayMapperAttr = "";
  40.  
  41.  
  42.  
  43. //  ========== makeMonochromRampAMW ==========
  44. //
  45. //  Description:
  46. //        Make the ramp monochromatic if it is connected
  47. //        to a doubleArray attribute (vs vectorArray).
  48. //
  49.  
  50. global proc  makeMonochromRampAMW( string $node, string $attr )
  51. {
  52.  
  53.     // Check if the attribute is of type doubleArray.
  54.     //
  55.     string    $dblAttrAry[] = `particle -q -ppd $node`;
  56.     int        $dblAttrCnt = size( $dblAttrAry );
  57.     int        $isDoubleArray = 0;
  58.  
  59.     for ($i = 0; $i < $dblAttrCnt; $i++)
  60.     {
  61.         if ($attr == $dblAttrAry[$i])
  62.         {
  63.             $isDoubleArray = 1;
  64.             break;
  65.         }
  66.     }
  67.  
  68.  
  69.     // If attribute is double array, then make the
  70.     // ramp monochromatic.
  71.     //
  72.     if ($isDoubleArray)
  73.     {
  74.         // Need to find the ramp node.
  75.         //
  76.         string    $cnctAry[];
  77.         string    $arrayMapperNode;
  78.         string    $rampNode;
  79.  
  80.         $cnctAry = `listConnections -s true -d false ($node+"."+$attr)`;
  81.         $arrayMapperNode = $cnctAry[0];
  82.         $cnctAry = `listConnections -s true -d false ($arrayMapperNode+".computeNode")`;
  83.         $rampNode = $cnctAry[0];
  84.  
  85.  
  86.         // Set the ramp colors and positions to a monochromatic ramp.
  87.         //
  88.         setAttr ($rampNode+".colorEntryList[0].color") -type double3 1 1 1 ;
  89.         setAttr ($rampNode+".colorEntryList[1].color") -type double3 0.5 0.5 0.5 ;
  90.         setAttr ($rampNode+".colorEntryList[2].color") -type double3 0 0 0 ;
  91.         setAttr ($rampNode+".colorEntryList[1].position") 0.5;
  92.         setAttr ($rampNode+".colorEntryList[2].position") 1.0;
  93.     }
  94.  
  95.  
  96. }  // makeMonochromRampAMW //
  97.  
  98.  
  99.  
  100. //  ========== okayAMW ==========
  101. //
  102. //  Description:
  103. //        Callback for the OK button. This builds the actual
  104. //        arrayMapper command string, and executes it.
  105. //
  106.  
  107. global proc  okayAMW( string $win, string $rowLyt )
  108. {
  109.     setParent $win;
  110.  
  111.     // Start building the command string.
  112.     //
  113.     global string    $gArrayMapperObject;
  114.     global string    $gArrayMapperAttr;
  115.     string            $cmd, $inU, $inV;
  116.  
  117.     $cmd = "arrayMapper -target "+$gArrayMapperObject+" -destAttr "+$gArrayMapperAttr;
  118.  
  119.  
  120.     // Determine inputU flag.
  121.     //
  122.     int        $uIndex = `optionMenu -q -select uSourceOM`;
  123.  
  124.     switch ($uIndex)
  125.     {
  126.         case 1 :
  127.             // do nothing
  128.             break;
  129.  
  130.         case 2 :
  131.             $cmd += " -inputU ageNormalized";
  132.             break;
  133.  
  134.         default:
  135.             $cmd += " -inputU "+`optionMenu -q -value uSourceOM`;
  136.             break;
  137.     }
  138.  
  139.  
  140.     // Determine inputV flag.
  141.     //
  142.     int        $vIndex = `optionMenu -q -select vSourceOM`;
  143.  
  144.     switch ($vIndex)
  145.     {
  146.         case 1 :
  147.             // do nothing
  148.             break;
  149.  
  150.         case 2 :
  151.             $cmd += " -inputV ageNormalized";
  152.             break;
  153.  
  154.         default:
  155.             $cmd += " -inputV "+`optionMenu -q -value vSourceOM`;
  156.             break;
  157.     }
  158.  
  159.  
  160.     // Determine -type flag.
  161.     //
  162.     int        $computeNode = `optionMenu -q -select mapOM`;
  163.  
  164.     switch ($computeNode)
  165.     {
  166.         case 1 :
  167.             // do nothing
  168.             break;
  169.  
  170.         case 2 :
  171.             $cmd += " -type ramp";
  172.             break;
  173.  
  174.         default :
  175.             // Any button after the first two, contains the name of
  176.             // a ramp node to use.
  177.             //
  178.             string    $nodeName = `optionMenu -q -v mapOM`;
  179.             $cmd += " -mapTo "+$nodeName;
  180.             break;
  181.     }
  182.  
  183.  
  184.     // Execute the arrayMapper command.
  185.     //
  186.     evalEcho( $cmd );
  187.     window -e -vis 0 $win;
  188.  
  189.  
  190.     // Special case for monochromatic rmap. If the destination
  191.     // attribute is a doubleArray, then fix the ramp to be
  192.     // monochormatic.
  193.     //
  194.     if ($computeNode == 2)
  195.     {
  196.         makeMonochromRampAMW( $gArrayMapperObject, $gArrayMapperAttr );
  197.     }
  198.  
  199.  
  200.     // If the row layout was specifed, then update it.
  201.     //
  202.     if (size( $rowLyt ))
  203.     {
  204.         AEgenericUpdateOneTextfield( $gArrayMapperObject, $gArrayMapperAttr, $rowLyt );
  205.     }
  206.  
  207.  
  208. }  // okayAMW //
  209.  
  210.  
  211.  
  212. //  ========== makeAttrName ==========
  213. //
  214. //  Description:
  215. //        Given an attribute name, insert the given character
  216. //        before the 'PP' characters if they are present.
  217. //
  218.  
  219. proc string  makeAttrName( string $char, string $name )
  220. {
  221.     string  $s1 = $char+"PP";
  222.     string    $s2 = substitute( "PP", $name, $s1 );
  223.  
  224.     if ($s2 == $name)
  225.     {
  226.         $s2 = $name+$char;
  227.     }
  228.  
  229.     return( $s2 );
  230.  
  231.  
  232. }  // makeAttrName //
  233.  
  234.  
  235.  
  236. //  ========== replaceBtns ==========
  237. //
  238. //  Description:
  239. //        Replace the buttons in the menu with 
  240. //        the new buttons.
  241. //
  242.  
  243. proc  replaceBtns( string $win, string $menu, string $newBtnAry[] )
  244. {
  245.  
  246.     setParent $win;
  247.  
  248.  
  249.     // Delete the old buttons.
  250.     //
  251.     string    $oldBtnAry[] = `optionMenu -q -ils $menu`;
  252.     int        $oldBtnCnt = size( $oldBtnAry );
  253.  
  254.     for ($i = 0; $i < $oldBtnCnt; $i++)
  255.     {
  256.         deleteUI $oldBtnAry[$i];
  257.     }
  258.  
  259.  
  260.     // Add the new buttons.
  261.     //
  262.     int        $newBtnCnt = size( $newBtnAry );
  263.  
  264.     for ($i = 0; $i < $newBtnCnt; $i++)
  265.     {
  266.         menuItem -p $menu -l $newBtnAry[$i];
  267.     }
  268.  
  269.  
  270. }  // replaceBtns //
  271.  
  272.  
  273.  
  274. //  ========== makeAryAttrList ==========
  275. //
  276. //  Description:
  277. //        Make a list of all array attributes available
  278. //        in the particle shape which are suitable for
  279. //        using as input attributes to the mapper node.
  280. //        Make sure to remove the given attribute because
  281. //        it is already being used as the output node.
  282. //        Also, remove the ageNormalized attribute because
  283. //        it is redundant with the "Particle's Age" item.
  284. //
  285.  
  286. proc string[]  makeAryAttrList( string $win, string $node, string $outAttr )
  287. {
  288.     string    $attrList[] = `particle -q -ppd $node`;
  289.     int        $attrCnt = size( $attrList );
  290.     string    $aryList[];
  291.     int        $len;
  292.     int        $outCnt = 0;
  293.  
  294.  
  295.     for ($i = 0; $i < $attrCnt; $i++)
  296.     {
  297.         if (($attrList[$i] != $outAttr) && ($attrList[$i] != "ageNormalized"))
  298.         {
  299.             $aryList[$outCnt++] = $attrList[$i];
  300.         }
  301.     }
  302.  
  303.  
  304.     return( $aryList );
  305.  
  306.  
  307. }  // makeAryAttrList //
  308.  
  309.  
  310.  
  311. //  ========== create ==========
  312. //
  313. //  SYNOPSIS
  314. //        Create the window and all the controls.
  315. //
  316.  
  317. proc  create( string $win )
  318. {
  319.  
  320.     // Create window and base container widgets.
  321.     //
  322.     window 
  323.         -title "Create Ramp Options"
  324.         -widthHeight 400 400
  325.         -minimizeButton false 
  326.         -maximizeButton false
  327.         -retain 
  328.         -sizeable true
  329.         -resizeToFitChildren false
  330.         $win;
  331.  
  332.     formLayout -nd 100 workLyt;
  333.  
  334.     text -l "none" headerTxt;
  335.         formLayout -e
  336.             -af headerTxt left 4
  337.             -af headerTxt top 4
  338.             workLyt;
  339.  
  340.     optionMenu -l "Input U" uSourceOM;
  341.         menuItem -l "<None>";
  342.         formLayout -e 
  343.             -af uSourceOM left 12 
  344.             -ac uSourceOM top 4 headerTxt
  345.             workLyt;
  346.  
  347.     optionMenu -l "Input V" vSourceOM;
  348.         menuItem -l "<None>";
  349.         formLayout -e 
  350.             -af vSourceOM left 12 
  351.             -ac vSourceOM top 4 uSourceOM
  352.             workLyt;
  353.  
  354.     optionMenu -l "Map To" mapOM;
  355.         menuItem -l "<None>";
  356.         formLayout -e 
  357.             -af mapOM left 10
  358.             -ac mapOM top 4 vSourceOM
  359.             workLyt;
  360.  
  361.     button -l "OK" -w 100 -h 26 okBtn;
  362.         formLayout -e 
  363.             -ap okBtn left -50 25 
  364.             -af okBtn bottom 4 
  365.             workLyt;
  366.  
  367.     button -l "Cancel" -w 100 -h 26 cancelBtn;
  368.         formLayout -e 
  369.             -ap cancelBtn left -50 75 
  370.             -af cancelBtn bottom 4 
  371.             workLyt;
  372.  
  373.     separator -horizontal true sep1;
  374.         formLayout -e
  375.             -af sep1 left 0
  376.             -af sep1 right 0
  377.             -ac sep1 bottom 4 okBtn
  378.             workLyt;
  379.  
  380.  
  381. }  // create //
  382.  
  383.  
  384.  
  385. //  ========== register ==========
  386. //
  387. //  Description:
  388. //        Register the callbacks on the widgets.
  389. //
  390.  
  391. proc  register( string $win )
  392. {
  393.  
  394.     setParent $win;
  395.  
  396.     button -e -c ("window -e -vis 0 "+$win) cancelBtn;
  397.  
  398.  
  399. }  // register //
  400.  
  401.  
  402.  
  403. //  ========== update ==========
  404. //
  405. //  Description:
  406. //        Build the option menus to reflect the current
  407. //        state of the scene.
  408. //
  409.  
  410. proc  update( string $win, string $node, string $dstAttr, string $rowLyt )
  411. {
  412.  
  413.     setParent $win;
  414.  
  415.  
  416.     // Put the attribute name in the header text.
  417.     //
  418.     text -e -l ("Destination Attribute: "+$dstAttr) headerTxt;
  419.  
  420.  
  421.     // Get the available list of array attributes.
  422.     //
  423.     string    $attrAry[] = makeAryAttrList( $win, $node, $dstAttr );
  424.     int        $attrCnt = size( $attrAry );
  425.  
  426.  
  427.     // Set the first two buttons for the input option menus.
  428.     //
  429.     string    $btnAry[];
  430.     $btnAry[0] = "<None>";
  431.     $btnAry[1] = "Particle's Age";
  432.  
  433.  
  434.     // Source U menu.
  435.     //
  436.     $btnAry[2] = makeAttrName( "U", $dstAttr );
  437.  
  438.     for ($i = 0; $i < $attrCnt; $i++)
  439.     {
  440.         $btnAry[$i+3] = $attrAry[$i];
  441.     }
  442.  
  443.     replaceBtns( $win, "uSourceOM", $btnAry );
  444.  
  445.  
  446.     // Source V menu.
  447.     //
  448.     $btnAry[2] = makeAttrName( "V", $dstAttr );
  449.     replaceBtns( $win, "vSourceOM", $btnAry );
  450.     optionMenu -e -sl 2 vSourceOM;
  451.  
  452.  
  453.     // Map menu.
  454.     //
  455.     string    $mapBtns[];
  456.     string    $rampAry[] = `ls -type ramp`;
  457.     int        $rampCnt = size( $rampAry );
  458.  
  459.     $mapBtns[0] = "<None>";
  460.     $mapBtns[1] = "New Ramp";
  461.  
  462.     for ($i = 0; $i < $rampCnt; $i++)
  463.     {
  464.         $mapBtns[$i+2] = $rampAry[$i];
  465.     }
  466.  
  467.     replaceBtns( $win, "mapOM", $mapBtns );
  468.     optionMenu -e -sl 2 mapOM;
  469.  
  470.  
  471.     // Need to register a new callback each time because
  472.     // the row layout changes. It gets passed in by
  473.     // the textfield popup menu.
  474.     //
  475.     button -e -c ("okayAMW "+$win+" "+$rowLyt) okBtn;
  476.  
  477.  
  478. }  // update //
  479.  
  480.  
  481.  
  482. //  ========== ArrayMapperWnd ==========
  483. //
  484. //  Description:
  485. //        Main entry point. Must be last procedure in file.
  486. //
  487.  
  488. global proc  ArrayMapperWnd( string $node, string $attr, string $rowLyt )
  489. {
  490.     string    $win = "ArrayMapperWnd";
  491.  
  492.     if (! `window -exists $win`)
  493.     {
  494.         create( $win );
  495.         register( $win );
  496.     }
  497.  
  498.     update( $win, $node, $attr, $rowLyt );
  499.  
  500.  
  501.     // Save the node name and attribute in a global
  502.     // variable, so the callback can get access to it.
  503.     //
  504.     global string    $gArrayMapperObject;
  505.     global string    $gArrayMapperAttr;
  506.  
  507.     $gArrayMapperObject = $node;
  508.     $gArrayMapperAttr = $attr;
  509.  
  510.     showWindow( $win );
  511.  
  512.  
  513. }  // ArrayMapperWnd //
  514.